package com.huobao.yunying.activitys;

import java.util.Map;

import org.xutils.view.annotation.ViewInject;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huobao.yunying.base.HuobaoBaseActivity;
import com.huobao.yunying.entity.Tuikuan;
import com.huobao.yunying.https.Http;
import com.huobao.yunying.https.HttpListener;
import com.huobao.yunying.https.HttpUtil;
import com.huobao.yunying.utils.ImageUtils;
import com.huobao.zhangying.R;

import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class Act_Tuikuan_detail extends HuobaoBaseActivity {

	@ViewInject(R.id.tv_1)
	private TextView tv_1;
	@ViewInject(R.id.tv_2)
	private TextView tv_2;
	@ViewInject(R.id.tv_3)
	private TextView tv_3;
	@ViewInject(R.id.tv_4)
	private TextView tv_4;
	@ViewInject(R.id.tv_5)
	private TextView tv_5;
	@ViewInject(R.id.tv_6)
	private TextView tv_6;
	@ViewInject(R.id.tv_7)
	private TextView tv_7;
	@ViewInject(R.id.tv_8)
	private TextView tv_8;
	@ViewInject(R.id.tv_9)
	private TextView tv_9;
	@ViewInject(R.id.tv_10)
	private TextView tv_10;
	@ViewInject(R.id.tv_11)
	private TextView tv_11;
	@ViewInject(R.id.image)
	private ImageView image;
	@ViewInject(R.id.btn_1)
	private Button btn_1;
	@ViewInject(R.id.btn_2)
	private Button btn_2;
	private String id;
	@Override
	protected int getContentView() {
		return R.layout.layout_tuikuan_detail;
	}

	@Override
	protected String getTitleText() {
		return "退款详情";
	}

	@Override
	protected void init() {
		id = getIntent().getStringExtra("id");
		getTuikuanDetail();
		btn_1.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Map<String, String> map = HttpUtil.getParams("app","buyerorder","act","cancel","refund_id",id);
				Http.getInstant().sendRequest(context, map, new HttpListener() {
					
					@Override
					public void onHttpSuccess(String result) {
						JSONObject jsonObject = JSON.parseObject(result);
						Toast.makeText(context, jsonObject.getString("retval"),Toast.LENGTH_SHORT).show();
					}
					
					@Override
					public void onHttpError(String error) {

					}
				});
			}
		});
		btn_2.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(context, Act_Ask_Tuihuo.class);
				intent.putExtra("data", tuikuan);
				startActivity(intent);
			}
		});
	}

	private void getTuikuanDetail(){
		Map<String, String> map = HttpUtil.getParams("app","sellerorder","act","refund_view","refund_id",id);
		Http.getInstant().sendRequest(context, map, new HttpListener() {
			
			@Override
			public void onHttpSuccess(String result) {
				JSONObject jsonObject = JSON.parseObject(result);
				Tuikuan tuikuan = JSON.parseObject(jsonObject.getString("retval"), Tuikuan.class);
				show(tuikuan);
			}
			
			@Override
			public void onHttpError(String error) {

			}
		});
	}

	private Tuikuan tuikuan;
	protected void show(Tuikuan tuikuan) {
		tv_1.append("退款退货编号:");
		tv_1.append(tuikuan.refund_sn);
		
		tv_2.append("申请时间:");
		tv_2.append(tuikuan.created);
		
		
		tv_3.append("退款状态:");
		tv_3.append(tuikuan.status_text);
		
		
		tv_4.append("商品总额:");
		tv_4.append(tuikuan.total_fee);
		
		tv_5.append("退款金额:");
		tv_5.append(tuikuan.refund_goods_fee);
		
		
		tv_5.append("(商品金额");
		tv_5.append(tuikuan.goods_fee+")");
		
		
		tv_6.append("退运费:");
		tv_6.append(tuikuan.refund_shipping_fee);
		
		
		tv_6.append("(分摊的运费");
		tv_6.append(tuikuan.shipping_fee+")");
		
		
		tv_7.append("退款原因:");
		tv_7.append(tuikuan.refund_reason);
		
		
		
		
		tv_8.append("退款说明:");
		tv_8.append(tuikuan.refund_desc);
		
		
		tv_9.append("商品退款总额:");
		tv_9.append(tuikuan.refund_fee);
		
		
		tv_10.append("收货情况:");
		tv_10.append(tuikuan.shipped_text);
		
		tv_11.setText(tuikuan.content);
		ImageUtils.loadimg(image, tuikuan.pic_url);
		if(tuikuan.status.equals("WAIT_SELLER_AGREE") || tuikuan.status.equals("SELLER_REFUSE_BUYER")){
			btn_1.setVisibility(View.VISIBLE);
			btn_2.setVisibility(View.VISIBLE);
		}else{
			btn_1.setVisibility(View.GONE);
			btn_2.setVisibility(View.GONE);
		}
	}
}
